package socket.socketandserversocket;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Demo01Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8080);
        System.out.println("服务器等待客户端...");
        BufferedInputStream bis;
        BufferedOutputStream bos;

        while (true) {
            Socket accept = serverSocket.accept();
            System.out.println("服务器收到客户端请求，双方可以互相通信");
            bis = new BufferedInputStream(accept.getInputStream());
            bos = new BufferedOutputStream(accept.getOutputStream());

            ReadThread readThread = new ReadThread(bis);
            WriteThread writeThread = new WriteThread(bos);
            new Thread(readThread, "服务器").start();
            new Thread(writeThread, "服务器").start();
        }
    }
}
